package cn.pkg.controller;

import cn.pkg.entities.Emp;
import cn.pkg.service.Empservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@RestController
public class EmpController {
    @Autowired
    private Empservice empservice;
    @PostMapping("/emp")
    public String addEmp(Emp emp){
        empservice.add(emp);
        return "add ok";
    }
    @GetMapping("/emp/{id}")
    public Object getEmpById(@PathVariable ("id") Long id){
//        单机锁的校验
        ExecutorService threadPool = Executors.newFixedThreadPool(300);
//        改用jmeter压测
//        for (int i = 0; i < 1000; i++) {
//                threadPool.submit(new Runnable() {
//                    @Override
//                    public void run() {
//                        empservice.getEmpById(id);
//                    }
//                });
//            }
        return empservice.getEmpById(id);
    }
}
